/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telsoft.data;

import com.telsoft.business.AttributesBusiness;
import com.telsoft.business.DAOHelperBusiness;
import com.telsoft.entity.AttributesEntity;
import com.telsoft.entity.ChildrenEntity;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author thieplv
 */
public class ChildrenDAO {

    private Connection conn;

    public List<ChildrenEntity> getChildren() throws SQLException {
        List<ChildrenEntity> children = new ArrayList<ChildrenEntity>();
        conn = DAOHelperBusiness.getConnection();
        Statement stm = DAOHelperBusiness.getStatement(conn);
        String sql = "SELECT * FROM CHILDREN_COMPONENT";
        ResultSet rs = stm.executeQuery(sql);
        while (rs.next()) {
            ChildrenEntity child = new ChildrenEntity();                     
            List<AttributesEntity> attrs = AttributesBusiness.getAttrsByChildID(rs.getInt("CHILD_ID"));
            child.setAttrs(attrs);
            child.setChildID(rs.getInt("CHILD_ID"));
            child.setCompID(rs.getInt("COM_ID"));
            child.setDetail(rs.getString("DETAIL"));
            children.add(child);
        }
        DAOHelperBusiness.closeResultSet(rs);
        DAOHelperBusiness.closeStatement(stm);
        DAOHelperBusiness.closeConnection(conn);
        return children;
    }
    
}
